//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Reflection;
using OpenLS.Core.Notification;

namespace OpenLS.Chart.UI.Internals
{
    public class ScatterSeriesObserver : ViewModelBase
    {
        public ScatterSeriesObserver(ScatterSeries series)
        {
            this.series = series;
            if (series.XValues is NumericDataSource)
            ((NumericDataSource)series.XValues).ValueChanged += XValues_ValueChanged;
            series.YValues.ValueChanged += YValues_ValueChanged;
        }

        private readonly ScatterSeries series;


        public IEnumerable<ScatterValue> Values
        {
            get
            {
                List<NumericValue> xValues = new List<NumericValue>(series.XNumericValues);
                var yValues = new List<NumericValue>(series.YValues.NumericValues);
                int count = Math.Min(xValues.Count, yValues.Count);
                for (int i = 0; i < count; i++)
                {
                    yield return new ScatterValue(xValues[i].Value, yValues[i].Value);
                }
            }
        }
        void YValues_ValueChanged(object sender, EventArgs e)
        {
            notifyPropertyChanged("Values");
        }

        void XValues_ValueChanged(object sender, EventArgs e)
        {
            notifyPropertyChanged("Values");
        }
    }
}